import { Header } from '../componets/header';
import { Carousel } from '../componets/carousel';
import { App } from './App';
import { BoardTitle } from '../componets/board_title';
import { ShowBoard } from '../componets/show_board';
import { Footer } from '../componets/footer';

class Index extends App {
  constructor () {
    super({
      swiper: true,
      phone: true,
      field: true
    });
  }
  render () {
    new Header(this.$app, this.cache.filedDatas, this.cache.phoneDatas).init();
    // 轮播图
    new Carousel(this.$app, this.cache.swiperDatas).init();
    new BoardTitle(this.$app, '手机上新').init();
    new ShowBoard(this.$app, this.filterDatas('new')).init();
    new BoardTitle(this.$app, '超值手机').init();
    new ShowBoard(this.$app, this.filterDatas('valuable')).init();
    new BoardTitle(this.$app, '官方推荐').init();
    new ShowBoard(this.$app, this.filterDatas('recom')).init();
    new Footer(this.$app).init();
    $('body').prepend(this.$app);
  }
  filterDatas (field) {
    return this.cache.phoneDatas.filter((item) => {
      switch (field) {
        case 'recom':
          return item.recom == 1;
          break;
        case 'new':
          return item.new == 1;
          break;
        case 'valuable':
          return item.most_value == 1;
        default:
          break;
      }
    })
  }
}

new Index();